﻿//This file is part of Search Engine by Tomasz Kusienicki.
// 
//This Search Engine is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//any later version.
// 
//Foobar is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
// 
//You should have received a copy of the GNU General Public License
//on <http://www.gnu.org/licenses/>.

using AdminApp1.Common;
using AdminApp1.DataSource;
using AdminApp1.Presenters;

namespace AdminApp1.Models
{
    public class MainModel : ModelBase<MainModel>
    {

        #region Connection
        public Connection Connection { get; set; }
        #endregion

        #region DataControl
        public DataControlModel DataControlModel { get; set; }
        public DataControlPresenter DataControlPresenter { get; set; }
        #endregion

        #region MsgTexts
        public string ApplicationName { get; set; }
        public string MsgConnecting { get; set; }
        public string MsgConnectionFail { get; set; }
        #endregion


        #region Server
        private string _server;
        public string Server
        {
            get { return _server ?? ""; }
            set
            {
                if (_server == value) return;
                _server = value;
                OnPropertyChanged("Server");
            }
        }
        #endregion

        #region Database
        private string _database;
        public string Database
        {
            get { return _database ?? ""; }
            set
            {
                if (_database == value) return;
                _database = value;
                OnPropertyChanged("Database");
            }
        }
        #endregion

        #region TrustedConnection
        private bool _trustedConnection;
        public bool TrustedConnection
        {
            get { return _trustedConnection; }
            set
            {
                if (_trustedConnection == value) return;
                _trustedConnection = value;
                OnPropertyChanged("TrustedConnection");
                OnPropertyChanged("ReversedTrustedConnection");

                if (!_trustedConnection) return;
                _user = string.Empty;
                OnPropertyChanged("User");
                _password = string.Empty;
                OnPropertyChanged("Password");
            }
        }

        public bool ReversedTrustedConnection
        {
            get { return !_trustedConnection; }
        }
        #endregion

        #region User
        private string _user;
        public string User
        {
            get { return _user ?? ""; }
            set
            {
                if (_trustedConnection || _user == value) return;
                _user = value;
                OnPropertyChanged("User");
            }
        }
        #endregion

        #region Password
        private string _password;
        public string Password
        {
            get { return _password ?? ""; }
            set
            {
                if (_trustedConnection || _password == value) return;
                _password = value;
                OnPropertyChanged("Password");
            }
        }
        #endregion

        #region RememberMe
        private bool _rememberMe;
        public bool RememberMe
        {
            get { return _rememberMe; }
            set
            {
                if (_rememberMe == value) return;
                _rememberMe = value;
                OnPropertyChanged("RememberMe");
            }
        }
        #endregion

    }
}
